unit DadosMFD;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Mask;

type
  TFormDadosMFD = class(TForm)
    BitBtn1: TBitBtn;
    Label1: TLabel;
    Edit1: TEdit;
    GroupBox4: TGroupBox;
    RB_Total: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    Label2: TLabel;
    MaskEdit1: TMaskEdit;
    Label3: TLabel;
    MaskEdit2: TMaskEdit;
    procedure BitBtn1Click(Sender: TObject);
    procedure RB_TotalClick(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormDadosMFD: TFormDadosMFD;
  cSerie:Array[0..20] of char;
  tipo:string = '0';

implementation

uses principal, Retorno, funcoesapoio, declaracoes;

{$R *.dfm}

procedure TFormDadosMFD.BitBtn1Click(Sender: TObject);
begin
        FormPrincipal.Statusbar1.Panels[0].Text:='Formato Dados MFD'; WaitProcess;
        if not FileExists('C:\SWEDA\MFD.BIN') Then
        begin
                resposta:= ECF_DownloadMFD('C:\SWEDA\MFD.BIN','0',' ', ' ','0');
                FormPrincipal.Memo1.Lines.Add('Download MFD:'+inttostr(Resposta));
        end;
        Resposta:= ECF_FormatoDadosMFD( 'C:\SWEDA\MFD.BIN', Edit1.Text,'0',tipo, MaskEdit1.Text, MaskEdit2.Text,'0' );

        FormPrincipal.Memo1.Lines.Add('Formato Dados MFD:'+inttostr(Resposta));
        FormPrincipal.Memo1.Lines.Add('');

        if Resposta = 1 then
        if MessageDlg('Deseja abrir o arquivo '+Edit1.Text+' ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
                FormPrincipal.OpenDialog1.FileName:=Edit1.Text ;
                FormPrincipal.OpenDialog1.Execute;
                FormRetorno.Caption:=FormPrincipal.OpenDialog1.FileName;
                FormRetorno.RichEdit1.Lines.LoadFromFile(FormPrincipal.OpenDialog1.FileName);
                FormRetorno.Show;
        end;

        VerificaRetornoFuncao(Resposta);
        Refresh;

end;

procedure TFormDadosMFD.RB_TotalClick(Sender: TObject);
begin
        MaskEdit1.Enabled:=False;
        MaskEdit2.Enabled:=False;
        MaskEdit1.Text:='';
        MaskEdit2.Text:='';
        tipo:='0';

end;

procedure TFormDadosMFD.RadioButton2Click(Sender: TObject);
begin
        MaskEdit1.EditMask:='!99/99/00;1;_';
        MaskEdit2.EditMask:='!99/99/00;1;_';
        MaskEdit1.Text:=FormatDateTime('dd/mm/yy',date);
        MaskEdit2.Text:=FormatDateTime('dd/mm/yy',date);
        MaskEdit1.Enabled:=True;
        MaskEdit2.Enabled:=True;
        tipo:='1';

end;

procedure TFormDadosMFD.RadioButton3Click(Sender: TObject);
begin
        MaskEdit1.Enabled:=True;
        MaskEdit2.Enabled:=True;
        MaskEdit1.EditMask:='!000000;1;_';
        MaskEdit2.EditMask:='!000000;1;_';
        MaskEdit1.Text:='000001';
        MaskEdit2.Text:='999999';

        tipo:='2';

end;

procedure TFormDadosMFD.FormShow(Sender: TObject);
begin
        cSerie[0]:=#0;
        FormPrincipal.Statusbar1.Panels[0].Text:='Número de Série'; WaitProcess;
        Resposta:= ECF_NumeroSerieMFD(cSerie);
        Edit1.Text:='C:\SWEDA\'+cSerie+'.TXT';
end;

end.
